package logic

import (
	"cart/cart"
	"context"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CartPriceLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCartPriceLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartPriceLogic {
	return &CartPriceLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CartPriceLogic) CartPrice(req *types.CartPriceRequest) (resp *types.Response, err error) {
	// todo: 购物车总金额
	price, err := l.svcCtx.CartRpc.CartPrice(l.ctx, &cart.CartPriceRequest{
		UserId:     req.UserId,
		GoodsId:    req.GoodsId,
		GoodsPrice: float32(req.GoodsPrice),
	})
	if err != nil {
		return &types.Response{
			Code: 500,
			Msg:  err.Error(),
			Data: nil,
		}, nil
	}
	return &types.Response{
		Code: 200,
		Msg:  "购物车计算成功",
		Data: price,
	}, nil
}
